<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="交易时间" prop="accountflowTime">
      <el-input v-model="dataForm.accountflowTime" placeholder="交易时间"></el-input>
    </el-form-item>
    <el-form-item label="交易类型，转账，充值，提现" prop="accountflowType">
      <el-input v-model="dataForm.accountflowType" placeholder="交易类型，转账，充值，提现"></el-input>
    </el-form-item>
    <el-form-item label="交易金额" prop="accountflowMoney">
      <el-input v-model="dataForm.accountflowMoney" placeholder="交易金额"></el-input>
    </el-form-item>
    <el-form-item label="收款账户名" prop="accountflowPayeeaccount">
      <el-input v-model="dataForm.accountflowPayeeaccount" placeholder="收款账户名"></el-input>
    </el-form-item>
    <el-form-item label="收款方姓名" prop="accountflowPayeename">
      <el-input v-model="dataForm.accountflowPayeename" placeholder="收款方姓名"></el-input>
    </el-form-item>
    <el-form-item label="付款方账户名" prop="accountflowPayeraccount">
      <el-input v-model="dataForm.accountflowPayeraccount" placeholder="付款方账户名"></el-input>
    </el-form-item>
    <el-form-item label="付款方姓名" prop="accountflowPayername">
      <el-input v-model="dataForm.accountflowPayername" placeholder="付款方姓名"></el-input>
    </el-form-item>
    <el-form-item label="账户余额" prop="accountflowBalance">
      <el-input v-model="dataForm.accountflowBalance" placeholder="账户余额"></el-input>
    </el-form-item>
    <el-form-item label="交易备注" prop="accountflowRemarks">
      <el-input v-model="dataForm.accountflowRemarks" placeholder="交易备注"></el-input>
    </el-form-item>
    <el-form-item label="交易状态，0交易失败，1交易成功" prop="accountflowStatus">
      <el-input v-model="dataForm.accountflowStatus" placeholder="交易状态，0交易失败，1交易成功"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          accountflowId: 0,
          accountflowTime: '',
          accountflowType: '',
          accountflowMoney: '',
          accountflowPayeeaccount: '',
          accountflowPayeename: '',
          accountflowPayeraccount: '',
          accountflowPayername: '',
          accountflowBalance: '',
          accountflowRemarks: '',
          accountflowStatus: ''
        },
        dataRule: {
          accountflowTime: [
            { required: true, message: '交易时间不能为空', trigger: 'blur' }
          ],
          accountflowType: [
            { required: true, message: '交易类型，转账，充值，提现不能为空', trigger: 'blur' }
          ],
          accountflowMoney: [
            { required: true, message: '交易金额不能为空', trigger: 'blur' }
          ],
          accountflowPayeeaccount: [
            { required: true, message: '收款账户名不能为空', trigger: 'blur' }
          ],
          accountflowPayeename: [
            { required: true, message: '收款方姓名不能为空', trigger: 'blur' }
          ],
          accountflowPayeraccount: [
            { required: true, message: '付款方账户名不能为空', trigger: 'blur' }
          ],
          accountflowPayername: [
            { required: true, message: '付款方姓名不能为空', trigger: 'blur' }
          ],
          accountflowBalance: [
            { required: true, message: '账户余额不能为空', trigger: 'blur' }
          ],
          accountflowRemarks: [
            { required: true, message: '交易备注不能为空', trigger: 'blur' }
          ],
          accountflowStatus: [
            { required: true, message: '交易状态，0交易失败，1交易成功不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.accountflowId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.accountflowId) {
            this.$http({
              url: this.$http.adornUrl(`/expect/accountflow/info/${this.dataForm.accountflowId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.accountflowTime = data.accountflow.accountflowTime
                this.dataForm.accountflowType = data.accountflow.accountflowType
                this.dataForm.accountflowMoney = data.accountflow.accountflowMoney
                this.dataForm.accountflowPayeeaccount = data.accountflow.accountflowPayeeaccount
                this.dataForm.accountflowPayeename = data.accountflow.accountflowPayeename
                this.dataForm.accountflowPayeraccount = data.accountflow.accountflowPayeraccount
                this.dataForm.accountflowPayername = data.accountflow.accountflowPayername
                this.dataForm.accountflowBalance = data.accountflow.accountflowBalance
                this.dataForm.accountflowRemarks = data.accountflow.accountflowRemarks
                this.dataForm.accountflowStatus = data.accountflow.accountflowStatus
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/expect/accountflow/${!this.dataForm.accountflowId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'accountflowId': this.dataForm.accountflowId || undefined,
                'accountflowTime': this.dataForm.accountflowTime,
                'accountflowType': this.dataForm.accountflowType,
                'accountflowMoney': this.dataForm.accountflowMoney,
                'accountflowPayeeaccount': this.dataForm.accountflowPayeeaccount,
                'accountflowPayeename': this.dataForm.accountflowPayeename,
                'accountflowPayeraccount': this.dataForm.accountflowPayeraccount,
                'accountflowPayername': this.dataForm.accountflowPayername,
                'accountflowBalance': this.dataForm.accountflowBalance,
                'accountflowRemarks': this.dataForm.accountflowRemarks,
                'accountflowStatus': this.dataForm.accountflowStatus
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
